package cn.org.seventh.web.common;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.filter.GenericFilterBean;

/**
 * @author <a href="mailto:young@hrzsoft.cn">Zhou Yang</a>
 * @version $Id: MultiPartFilter.java 32 2005-11-22 10:18:21Z young $
 */
public class MultiPartFilter extends GenericFilterBean {

    public void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) servletRequest;

        String content_type = request.getContentType();
        if (content_type != null
                && content_type.indexOf("multipart/form-data") != -1) {
            request = new JakartaMultiPartRequest(request, getFilterConfig()
                    .getInitParameter("saveDir"), Integer.valueOf(
                    getFilterConfig().getInitParameter("maxUploadSize"))
                    .intValue());
        }
        filterChain.doFilter(request, servletResponse);
    }

}
